/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T22A_heter_bycareg_educ.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}/panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
Table A22: Heterogeneity of impact: caregiver education

*******************************************************************************/

forvalues num=2/3 {
	gen group`num'_lowed=group`num'*lowed
	gen group`num'_highed=group`num'*(1-lowed)	
}

label var group2_lowed "Low educated mothers _NEP Basico"
label var group2_highed "High educated mothers _NEP Basico"
label var group3_lowed "Low educated mothers _NEP Intensivo"
label var group3_highed "High educated mothers _NEP Intensivo"

local finaloutcomes " zptevir_irtscore2 zcog_index zsoc_index" 
local list1 "finaloutcomes" 

eststo clear
foreach f of local list1 {

  foreach var of local `f' {
    *PANEL 1: ITT EDUCATION;
      xi: xtreg `var' group2_lowed group2_highed lowed group3_lowed group3_highed, fe i(CENTRO_SALUD)
      estimates store `var'_ED
      test group2_lowed-group2_highed==0
      estadd scalar p2=r(p)
      test group3_lowed - group3_highed==0
      estadd scalar p3=r(p)

      test group2_lowed=group3_lowed
      estadd scalar lowedp=r(p)
      test group2_highed =group3_highed
      estadd scalar highedp=r(p)
    
      qui sum `var' if e(sample) & TIPO==1
      estadd scalar mean_y=r(mean)	
  }
}

esttab zptevir_irtscore2_ED zcog_index_ED zsoc_index_ED                       ///
  using "${out_tables}/appendix/T22A_heter_bycareg_educ.csv", replace f   ///	    
  keep(group2_lowed group2_highed group3_lowed group3_highed )                ///
  cells("b(fmt(3)star)" "se(fmt(3)par)")                                      ///
  star(* 0.10 ** 0.05 *** 0.01)                                               ///
  stats(r2 p2 p3 N, fmt(2 3 3 0)                                              ///
  labels("R-squared" "P-value Lowed=Highed: NEP-B" "P-value Lowed=Highed: NEP-I" "Observations")) legend ///
  varlabels(group2_lowed "NEP-B Low Education" group2_highed "NEP-B High Education" group3_lowed "NEP-I  Low Education" group3_highed "NEP-I High Education") ///
  mtitles("Vocabulary Index" "Exec. Function Index" "Socioemotional Index" )  								 


		
